<template>
  <div class="user-card new-chat" @click="toggleUserSet">
    <i class="fa-solid fa-user" style="font-size: 25px; color: black;"></i>
    <span class="user-name new-chat-title">{{ userName }}</span>
    <div class="user-setting" v-if="isUserSetOpen" @click.stop>
      <div class="setting-item">
        <span class="user-name new-chat-title">{{ userName }}</span>
      </div>
      <div class="setting-item" @click="$emit('logout')">
        <span class="user-name new-chat-title">
          <i class="fa-solid fa-arrow-right-from-bracket" style="margin-right: 5px;"></i>
          注销
        </span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'UserCard',
  props: {
    userName: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      isUserSetOpen: false
    }
  },
  methods: {
    toggleUserSet() {
      this.isUserSetOpen = !this.isUserSetOpen
    }
  },
  emits: ['logout']
}
</script>

<style scoped>
.user-card {
  margin-top: auto;
  padding: 15px;
  background-color: #ffffff;
  border-top: 1px solid #e6e6e6;
}

.user-info {
  display: flex;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.user-info:hover {
  background-color: #f5f7fa;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #409eff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 18px;
  margin-right: 10px;
}

.user-name {
  flex: 1;
  color: #333333;
  font-size: 14px;
}

.user-setting {
  position: absolute;
  bottom: 70px;
  left: 15px;
  right: 15px;
  background-color: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  overflow: hidden;
  z-index: 1000;
}

.setting-item {
  padding: 12px 15px;
  display: flex;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.3s;
}

.setting-item:hover {
  background-color: #f5f7fa;
}

.setting-item i {
  margin-right: 10px;
  color: #409eff;
  font-size: 16px;
}

.setting-item span {
  color: #333333;
  font-size: 14px;
}

.setting-item.logout {
  border-top: 1px solid #e6e6e6;
}

.setting-item.logout i {
  color: #f56c6c;
}

.setting-item.logout span {
  color: #f56c6c;
}

.new-chat {
  padding: 5px;
  height: 40px;
  display: flex;
  align-items: center;
  border-radius: 10px;
}

.new-chat:hover {
  background-color: #579ef4;
  cursor: pointer;
  transition: 0.3s;
}

.new-chat-title {
  flex: 1;
  padding-left: 10px;
}
</style> 